---
title: Assign the claim-grouped sort key
summary: Compute the "my tasks" grouping/sort key for a task row.
status: draft
owner: SAIF Documentation
last_reviewed: 2026-08-21
library: SAIF.Business.Tasks.Claim
reference_type: embedded
operation_id: OP-7
trigger: Called from Add and from AfterRetrieve per row
---

# Assign the claim-grouped sort key

Computes the grouping key used to float claims with an urgent task to the top of the "my tasks" list.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-7 |
| **Trigger** | Called from `Add` and from `AfterRetrieve` per row |
| **Inputs** | Task row, previous row's latched grouping state |
| **Outputs** | `task.sortBy` assigned |
| **Primary components** | `clsMyTaskCollection.setSortOrder` |
| **Entry point** | `SAIF.Business.Tasks.Claim/clsMyTaskCollection.vb` |

## Steps

1. When the row's `ClaimID` differs from the previous row's, latch a new grouping state: if `PriorityCode = "URG"`, set the "priority" flag and use the `ClaimID` itself as the group sort number; otherwise clear the flag.
2. Assign `task.sortBy` = the latched claim ID for urgent groups, otherwise the constant `100000000000000`, so claims with an urgent task float to the top and all remaining tasks share one bucket ordered by date/claim ([BR-MY-02](../business-rules.md#br-my-02-urgent-claims-grouped-ahead-in-my-tasks-sort)).*

## Process flow

```mermaid
flowchart TD
	Start([setSortOrder called]) --> Check{"ClaimID differs from<br>previous?"}
	Check -->|Yes| Latch{PriorityCode = URG?}
	Latch -->|Yes| SetFlag[Latch priority flag,<br>use ClaimID as group key]
	Latch -->|No| ClearFlag[Clear priority flag]
	Check -->|No| Assign
	SetFlag --> Assign[Assign sortBy]
	ClearFlag --> Assign
	Assign --> EndOk([sortBy assigned])
```

## Failure and edge-case behavior
- All non-urgent tasks share one flat sort bucket (`100000000000000`); the incrementing variant is commented out in source, so whether the flat bucket is intended is unclear.*

## Related documentation
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)
- [SQL catalog](../sql/index.md)
- [Database tables](../database-tables.md)

## Sources
- SAIF.Business.Tasks.Claim/clsMyTaskCollection.vb
